est drop _all

* mainpath should be set to the Replication package base directory
global mainpath ".."

* MP surprises
import excel "$mainpath\data\fomc_bauer_swanson.xlsx", sheet("FOMC Announcements") firstrow clear
destring MP* SP500*, replace force
collapse (sum) MP* Unscheduled SP500*, by(Date)
drop if mi(Date)
tempfile mps
save `mps', replace

* baseline coefficients
import delimited "$mainpath\output\bluechip_rule_regressions.csv", varnames(1) clear 
gen ym = mofd(date(date,"YMD"))
format ym %tm
order ym
tsset ym
tempfile gamma_regs
save `gamma_regs'

* inertial coefficients
import delimited "..\output\bluechip_rule_inertial.csv", varnames(1) clear 
gen ym = mofd(date(date,"YMD"))
format ym %tm
order ym
tsset ym
rename gamma gamma_fe_inertial
tempfile gamma_ssm
save `gamma_ssm'

clear

* stock returns
use "$mainpath\data\vwretd_daily"
rename caldt Date
merge 1:1 Date using `mps'
drop _merge

gen ym=mofd(Date)

merge m:1 ym using `gamma_regs'
drop _merge
merge m:1 ym using `gamma_ssm'
drop _merge

drop if mi(gamma_fe)

tsset Date


* Interactions
gen gvar = .
gen mps_X_gvar = .

replace vwretd = vwretd*100

local i 0
foreach rvar of varlist vwretd SP500emini {

	reg `rvar' MPS if ~mi(MPS), ro
	est store m`i++'

	foreach var of varlist gamma_fe gamma_fe_inertial {
		replace gvar = `var'
		replace mps_X_gvar = MPS*gvar
	
		reg `rvar' MPS gvar mps_X_gvar if ~mi(MPS), ro
		est store m`i++'
	}
}

esttab m* using "$mainpath\tables\bk.tex", star(* .10 ** .05 *** .01)  b(a2) se(a2) nomtitle replace r2(2) noobs

